package com.team5101.service.impl;


import com.team5101.dao.INextFilmDao;
import com.team5101.dao.INowFilmDao;
import com.team5101.entity.NextFilm;
import com.team5101.entity.NowFilm;
import com.team5101.service.IHotFsService;
import com.team5101.service.INextFilmService;
import com.team5101.utils.DateSubUtil;
import com.team5101.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

 @Service
public class NextFilmServiceImpl implements INextFilmService {

     @Autowired
     private INextFilmDao nextFilmDao;

    @Autowired
    private INowFilmDao nowFilmDao;

     public List<NextFilm> getList() {
        return nextFilmDao.getList();
     }

     public NextFilm getfilm(Integer nfId) {
         return nextFilmDao.getfilm(nfId);
     }
     //需要判断是否上映值是否为1   是的话需要添加至上映表内
     @Transactional
     public int updatafilm(NextFilm nextFilm) {
         Integer nfChangeon = nextFilm.getNfChangeon();
         if (nfChangeon==1){
             NowFilm nowFilm = new NowFilm();
             nowFilm.setFnActor(nextFilm.getNfActor());
             nowFilm.setFnDirector( nextFilm.getNfDirector());
             nowFilm.setId(nextFilm.getNfId());
             nowFilm.setFnImg(nextFilm.getNfImg());
             nowFilm.setFnName(nextFilm.getNfName());
             nowFilm.setFnishow(nextFilm.getNfIshow());
             nowFilm.setFnTime(nextFilm.getNfLongtime());
             nowFilm.setFnPrice(nextFilm.getNfPrice());
             int addfilmfromnextfilm = nowFilmDao.addfilmfromnextfilm(nowFilm);

             return nextFilmDao.deletefilm(nextFilm.getId());

         }
         return nextFilmDao.updatafilm(nextFilm);
     }

     public int addfilm(NextFilm nextFilm) {
                nextFilm.setNfChangedown(0);
                nextFilm.setNfChangeon(0);
                nextFilm.setNfId(DateUtil.getid());
         return nextFilmDao.addfilm(nextFilm);
     }

     public int deletefilm(Integer id) {
         return nextFilmDao.deletefilm(id);
     }

     public List<NextFilm> getListByName(String nfName) {
         return nextFilmDao.getListByName(nfName);
     }
 }
